<template>
    <div class="region">
        <div class="content">
            <div class="left">地区</div>
            <ul>
                <li :class="{ active: activeFlag == '' }" @click="changeCity('')">全部</li>
                <li v-for="(item, index) in levelArr" @click="changeCity(item.value)" :key="index"
                    :class="{ active: activeFlag == item.value }">{{ item.name }}</li>
            </ul>

        </div>
    </div>
</template>

<script setup lang="ts">
import { reqhospitalLevelRegion } from '@/api/home';
import { onMounted, ref } from 'vue';
import type { HOSPITALLEVELANDREGIONResponse, HOSPITALLEVELANDREGIONArr } from '@/api/home/type';
//存放等级数据
let levelArr = ref<HOSPITALLEVELANDREGIONArr>([])
//控制等级高亮数组
let activeFlag = ref<string>('')
onMounted(
    () => {
        GetLevel()
    })

let GetLevel = async () => {
    let result: HOSPITALLEVELANDREGIONResponse = await reqhospitalLevelRegion('Beijin');
    //存取医院等级数据
    levelArr.value = result.data
    // console.log('我是等级数据', levelArr);
}
//城市对应的值
let changeCity = (value: string) => {
    activeFlag.value = value
    $emit('getRegion', value)
}
let $emit = defineEmits(['getRegion'])
</script>
<script lang="ts">
export default {
    name: 'Region'
}
</script>
<style scoped lang="scss">
.region {
    color: #7f7f7f;
    font-weight: 20px;
    margin-top: 10px;

    .content {
        display: flex;

        .left {
            width: 50px;
            margin-right: 10px;
        }

        ul {
            display: flex;
            flex-wrap: wrap;
        }

        li {
            margin-right: 10px;

            &.active {
                color: #55a6fe;
            }
        }

        li:hover {
            color: #55a6fe;
            cursor: pointer;
        }
    }
}
</style>